package com.loong.controller;

import com.loong.dto.StudentDTO;
import com.loong.entity.Student;
import com.loong.result.PageBean;
import com.loong.result.Result;
import com.loong.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;

    @GetMapping
    public Result<PageBean> list(StudentDTO studentDTO) {
        return Result.success(studentService.list(studentDTO));
    }

    @GetMapping("/list")
    public Result<List<Student>> listAll() {
        return Result.success(studentService.listAll());
    }

    @GetMapping("/{id}")
    public Result<Student> get(@PathVariable Integer id) {
        return Result.success(studentService.get(id));
    }

    @DeleteMapping("/{ids}")
    public Result<?> delete(@PathVariable("ids") List<Integer> ids) {
        studentService.delete(ids);
        return Result.success();
    }

    @PostMapping
    public Result<?> insert(@RequestBody Student student) {
        studentService.insert(student);
        return Result.success();
    }

    @PutMapping
    public Result<?> update(@RequestBody Student student) {
        studentService.update(student);
        return Result.success();
    }

    @PutMapping("/violation/{id}/{score}")
    public Result<?> violation(@PathVariable Integer id, @PathVariable Short score) {
        studentService.violation(id, score);
        return Result.success();
    }
}
